#! /bin/mksh

. $(realpath "$0" | xargs dirname)/../menu/dmenuconf

EXCON="jack_connect"
EXDISCON="jack_disconnect"

PulseClient="PulseAudio JACK Source-01"
MicClient="ardour:MicFiltered"
KbdClient="ardour:MidiFiltered"
DdbClient="deadbeef"

PulseClientL="${PulseClient}:front-left"
PulseClientR="${PulseClient}:front-right"
MicClientOutL="${MicClient}/audio_out 1"
MicClientOutR="${MicClient}/audio_out 2"
KbdClientOutL="${KbdClient}/audio_out 1"
KbdClientOutR="${KbdClient}/audio_out 2"
DdbClientOutL="${DdbClient}:deadbeef_1"
DdbClientOutR="${DdbClient}:deadbeef_2"

DLIST="\
mic-pulse-connect
mic-pulse-disconnect
deadbeef-pulse-connect
deadbeef-pulse-disconnect
midi-pulse-connect
midi-pulse-disconnect
"

AAA="$(echo -e "$DLIST" | dmenu -i -b -p WINE  -nb "$DMENUBG" -nf "$DMENUFG" -sb "$DMENUFG" -sf "$DMENUBG" -fn "$DMENUFONT")"

case "$AAA" in
	"mic-pulse-connect")         $EXCON    "$MicClientOutL" "$PulseClientL"    && $EXCON "$MicClientOutR" "$PulseClientR" ;;
	"mic-pulse-disconnect")      $EXDISCON "$MicClientOutL" "$PulseClientL" && $EXDISCON "$MicClientOutR" "$PulseClientR" ;;
	"deadbeef-pulse-connect")    $EXCON    "$DdbClientOutL" "$PulseClientL"    && $EXCON "$DdbClientOutR" "$PulseClientR" ;;
	"deadbeef-pulse-disconnect") $EXDISCON "$DdbClientOutL" "$PulseClientL" && $EXDISCON "$DdbClientOutR" "$PulseClientR" ;;
	"midi-pulse-connect")        $EXCON    "$KbdClientOutL" "$PulseClientL"    && $EXCON "$KbdClientOutR" "$PulseClientR" ;;
	"midi-pulse-disconnect")     $EXDISCON "$KbdClientOutL" "$PulseClientL" && $EXDISCON "$KbdClientOutR" "$PulseClientR" ;;
esac

exit 0
